const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');

async function main() {

  console.log(chalk.blue(`[change-version] info: start to change root package version according @nexusui/components version. It will be used as a release tag for CI builder.`));
  
  const rootWorkspace = path.resolve(__dirname, '..');
  const package = await fs.readJSON(path.join(rootWorkspace, 'package.json'));

  const components = await fs.readJSON(
    path.join(path.resolve(__dirname, '../packages/joseph-composite'), 'package.json')
  );

  package.version = components.version;
  await fs.writeJSON(path.join(rootWorkspace, 'package.json'), package, { spaces: 2 });
  
  console.log(chalk.green(`[change-version] info: root package version changed to ${package.version}.`));
}

main();
